package com.zhihao.zhihaopicturebackend.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zhihao.zhihaopicturebackend.api.aliyunai.model.CreateOutPaintingTaskResponse;
import com.zhihao.zhihaopicturebackend.common.DeleteRequest;
import com.zhihao.zhihaopicturebackend.model.dto.picture.*;
import com.zhihao.zhihaopicturebackend.model.entity.ServicePicture;
import com.zhihao.zhihaopicturebackend.model.entity.SystemUser;
import com.zhihao.zhihaopicturebackend.model.vo.PictureVO;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
* @author Jackson
* @description 针对表【service_picture(图片表)】的数据库操作Service
* @createDate 2024-12-23 16:19:52
*/
public interface ServicePictureService extends IService<ServicePicture> {

    /**
     * 上传图片  
     *
     * @param inputSource 文件
     * @param pictureUploadRequest id or not
     * @param loginUser 当前登录用户
     * @return
     */
    PictureVO uploadPicture(Object inputSource,
                            PictureUploadRequest pictureUploadRequest,
                            SystemUser loginUser);

    /**
     * 删除图片
     * @author Jackson
     * @date 2024-12-24 22:04
     * @return boolean
     **/
    boolean deletePicture(@Valid DeleteRequest deleteRequest, SystemUser loginUser);

    /**
     * 编辑图片
     * @author Jackson
     * @date 2024-12-24 22:00
     **/
    void editPicture(PictureEditRequest pictureEditRequest, SystemUser loginUser);

    /**
     * 图片审核
     *
     * @param pictureReviewRequest
     * @param loginUser
     */
    void doPictureReview(PictureReviewRequest pictureReviewRequest, SystemUser loginUser);

    /**
     * 批量抓取和创建图片
     *
     * @param pictureUploadByBatchRequest 批量抓取图片请求
     * @param loginUser 当前登录用户
     * @return 成功创建的图片数
     */
    Integer uploadPictureByBatch(@Valid PictureUploadByBatchRequest pictureUploadByBatchRequest, SystemUser loginUser);

    /**
     * 分页获取图片列表-多级缓存
     *
     * @param pictureQueryRequest 批量抓取图片请求
     * @return 分页信息列表
     */
    Page<PictureVO> listPictureVOByPageWithCache(PictureQueryRequest pictureQueryRequest, HttpServletRequest request);

    /**
     * 封装图像类分页查询(/全查询)条件构造方法
     * @param pictureQueryRequest
     * @return
     */
    QueryWrapper<ServicePicture> getQueryWrapper(PictureQueryRequest pictureQueryRequest);

    // 封装方法 为原有的图片关联创建用户的信息
    PictureVO getPictureVO(ServicePicture picture, HttpServletRequest request);

    Page<PictureVO> getPictureVOPage(Page<ServicePicture> picturePage, HttpServletRequest request);

    /**
     * 管理员自动过审并且填充审核参数；用户上传或编辑图片时，图片的状态会被重置为“待审核”
     * @param picture 图片
     * @param loginUser 登录用户
     */
    void fillReviewParams(ServicePicture picture, SystemUser loginUser);

    /**
     * 按颜色搜图(从用户空间中查询指定颜色相似图片)
     */
    List<PictureVO> searchPictureByColor(Long spaceId, String picColor, SystemUser loginUser);

    /**
     * 批量修改图片(从用户空间中查询指定颜色相似图片)
     */
    @Transactional(rollbackFor = Exception.class)
    void editPictureByBatch(PictureEditByBatchRequest pictureEditByBatchRequest, SystemUser loginUser);

    /**
     * 创建AI扩图任务
     */
    CreateOutPaintingTaskResponse createPictureOutPaintingTask(CreatePictureOutPaintingTaskRequest createPictureOutPaintingTaskRequest, SystemUser loginUser);

    /*
        删除空间图片/修改空间图片的权限校验(主要是校验用户空间的所属性)
     */
    void checkPictureAuth(SystemUser loginUser, ServicePicture picture);

}
